import { defineStore } from 'pinia'
import { ref } from 'vue'
import {userGetInfoService} from "@/api/user.js";
export const useUserStore = defineStore(
  'big-user',
  () => {
    // eslint-disable-next-line no-undef
    const token = ref(' ')
    const setToken = (newtoken) => {
      token.value = newtoken
    }
    const removeToken = () => {
      token.value = ''
    }

    //这里就是存储用户的数据
    const user = ref({})
    const getUser = async () => {
      const res = await userGetInfoService()
      user.value = res.data.data
    }
    // 这个就是obj就是一个对象，通过出传入空的对象，进行user信息的重置
    const setUser = (obj) => {
      user.value = obj
    }

    return {
      user,
      token,
      setToken,
      removeToken,
      getUser,
      setUser
    }
  },
  // 这里是对存入pinia仓库的数据进行持久化
  {
    persist: true
  }
)
